/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.inventory.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.inventory.dao.StoreInventoryCheckDetailDao;
import com.chlitina.store.modules.inventory.entity.StoreInventoryCheckDetail;

/**
 * 库存盘点明细Service
 * @author lvbo
 * @version 2013-11-18
 */
@Component
@Transactional(readOnly = true)
public class StoreInventoryCheckDetailService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(StoreInventoryCheckDetailService.class);
	
	@Autowired
	private StoreInventoryCheckDetailDao storeInventoryCheckDetailDao;
	
	public StoreInventoryCheckDetail get(Long id) {
		return storeInventoryCheckDetailDao.findOne(id);
	}
	
	public Page<StoreInventoryCheckDetail> find(Page<StoreInventoryCheckDetail> page, StoreInventoryCheckDetail storeInventoryCheckDetail, String inventoryCheckId) {
		DetachedCriteria dc = storeInventoryCheckDetailDao.createDetachedCriteria();
		if (inventoryCheckId != null) {
			dc.add(Restrictions.eq("storeInventoryCheck.id", Long.parseLong(inventoryCheckId)));
		}
		dc.addOrder(Order.desc("id"));
		return storeInventoryCheckDetailDao.find(page, dc);
	}
	
	public List<StoreInventoryCheckDetail> getByCheckId(Long id){
		DetachedCriteria dc = storeInventoryCheckDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq("storeInventoryCheck.id", id));
		dc.addOrder(Order.desc("id"));
		return storeInventoryCheckDetailDao.find(dc);
	}
	
	@Transactional(readOnly = false)
	public void save(StoreInventoryCheckDetail storeInventoryCheckDetail) {
		storeInventoryCheckDetailDao.save(storeInventoryCheckDetail);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		storeInventoryCheckDetailDao.delete(id);
	}
	
}
